<%@page import="eduboat.comm.util.ReturnConstant"%>
<%@page import="eduboat.dsch.comm.util.AdminMenuConstant"%>
<%@page contentType="text/html; charset=utf-8" %>
<%-- 
/**
 * 创建信息
 * ============= jsp名: /work/admin/xtgl/menu/menu_index.jsp
 * 页面作用描述:  菜单树页面，查询，保存，修改和删除
 * 创建人：鲜虎
 * 创建时间： 2013-1-25 
 * 修改信息1=============
 * 修改类型: //1.修改bug 2.业务变化修改 
 * 修改描述: 
 * 修改人： 
 * 修改时间：
 */
 --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>学舟智能教学平台-菜单管理</title>
<%@ include file="/comm/jsp/public.jsp"%>
<link rel="stylesheet" type="text/css" media="all" href="<%=path%>/work/comm/css/common.css" />
<!--顶部logocss-->
<link rel="stylesheet" type="text/css" media="all" href="<%=path%>/work/comm/css/head.css" />
<!--导航菜单css-->
<link rel="stylesheet" type="text/css" media="all" href="<%=path%>/work/comm/css/menu.css" />

<link href="<%=path%>/work/comm/css/step.css" rel="stylesheet" type="text/css" />
<!--通用js-->
<script type="text/javascript" src="<%=path %>/work/comm/js/public.js"></script>
<!--菜单操作js-->
<script type="text/javascript" src="<%=path %>/work/comm/js/nav.js"></script>
<!--返回顶部-->
<script type="text/javascript" src="<%=path %>/work/comm/js/backtotop.js"></script>
<!--树形css-->
<link rel="stylesheet" href="<%=path%>/comm/plug/tree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!--树形基本js-->
<script type="text/javascript" src="<%=path%>/comm/plug/tree/js/jquery.ztree.core-3.5.js"></script>
<!--表单验证css-->
<link rel="stylesheet" href="<%=path%>/comm/plug/validateform/validationEngine.jquery.css" type="text/css"/>
<!--表单验证js-->
<script src="<%=path%>/comm/plug/validateform/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=path%>/comm/plug/validateform/jquery.validationEngine-zh_CN.js" type="text/javascript" charset="utf-8"></script>
<SCRIPT type="text/javascript">
//创建顶层菜单时用
var defaultdata;
$(function(){
	//加载树
	 initMenuTreeData();	 
	 defaultdata=$("#inintdata").html();
	 var men_code=$("#men_code").val();
	 $("#form1").validationEngine({
			ajaxFormValidation: true,//开启表单提交校验
			ajaxFormValidationMethod: 'post',
			ajaxFormValidationURL:"<%=path%>/work/admin/xtgl/json/xt_men_checkForm.action",
			onAjaxFormComplete: edit//调用后执行方法
		});
});
/**
 * 加载树
 */
function initMenuTreeData(){
	ajaxListInitCall({
		url : "<%=path%>/work/admin/xtgl/json/xt_men_list.action", //访问页面 
		_callBackOK:initTreeOK,
		beforeSend : function(XMLHttpRequest) {
			$("#tree1_load").css("display","");
			$("#tree1").css("display","none");
	    },
		_errMethod:function(){
			$("#tree1").html("加载失败,请<a href=\"javascript:initTree()\">重试</a>");
			$("#tree1_load").css("display","none");
			
		}
	});
}
var setting = {
			data: {simpleData: {enable:true}},
			callback: {onClick: onSelect}
		     };
//后台成功返回后执行
function initTreeOK(data){
	var obj=data.listVO;
	var zNodes;
    for(var ss in obj)
       {
 	   obj[ss].id=obj[ss].men_sn;
 	   obj[ss].pId=obj[ss].parent_sn;
 	   obj[ss].name=obj[ss].men_name;
       }
    zNodes=obj;
    $.fn.zTree.init($("#tree1"), setting,zNodes);
    $("#tree1").css("display","");
    $("#tree1_load").css("display","none");
}
$.validationEngineLanguage.allRules["checkXt_code"] = {	
		"url": "<%=path%>/work/admin/xtgl/json/xt_men_keyUnique.action",
		"extraDataDynamic":["#old_men_code","#men_code"],
	    "alertTextOk": "* 此菜单编码可以使用",
	    "alertText": "* 此菜单编码已被使用",
	    "alertTextLoad": "* 检测菜单编码是否可用，请稍等。"
	};
function onSelect(event, treeId, treeNode){
 			setVO(treeNode);
 			$("#btu_addsub").show();
 			$("#btu_del").show();
 			return true;   
 	     }
function isNull(str,def){
 			if (str == "null" || str == "" || !str)
 			 {
 				 if(typeof(def)!="undefined")
 					 return def;
 				 else
 			         return "";
 			 }else{
 	 			return str;
 			 }
 		 }
function edit(status, form, json, options){
 			 if(status){
 			 var dialog;
		     var id=isNull($("#men_sn").val());
		     ajaxOtherCall({
				url : "<%=path%>/work/admin/xtgl/json/xt_men_save.action", //访问页面
				data:{
 						"xt_menVO.men_sn":isNull($("#men_sn").val()),
 						"xt_menVO.parent_sn":isNull($("#parent_sn").val()),
 						"xt_menVO.level_index":isNull($("#level_index").val()),
 						"xt_menVO.fomcat":isNull($("#fomcat").val()),
 						"xt_menVO.men_name":isNull($("#men_name").val()),
 						"xt_menVO.men_url":isNull($("#men_url").val()),
 						"xt_menVO.level_seq":isNull($("#level_seq").val()),
 						"xt_menVO.men_code":isNull($("#men_code").val())
 					 },
				_callBackOK:function(data){
					art.dialog.alert("保存成功!");
					initMenuTreeData();
					setVO(data.xt_menVO);
			 		$("#btu_addsub").show();
			 		$("#btu_del").show();
				}
			});
 		 }
 		 }
function del(){
			 art.dialog.confirm("你确认要删除吗?<br/><br/>如果是父节点下面的子节点也会一起删除!",function(){
				 ajaxdel(); 
			 });
		     
 		}
function ajaxdel(){
 			 var id=isNull($("#men_sn").val());
 			ajaxOtherCall({
					url : "<%=path%>/work/admin/xtgl/json/xt_men_del.action", //访问页面
					data:{
						"xt_menVO.fomcat":isNull($("#fomcat").val())
	 					 },
					_callBackOK:function(data){
						delNodeById(id);
						$("#inintdata").html(defaultdata); 
						art.dialog.alert("删除成功!");
					}
				});
}
function addsubmenu(){
 			 //初始化子菜单
 			 var fomcat=$("#fomcat").val();
 			 var men_sn=$("#men_sn").val();
 			 var level_index=$("#level_index").val();
 			$("#inintdata").html(defaultdata);
 			$("#parent_sn").val(isNull(men_sn));
 			$("#fomcat").val(fomcat);
 			$("#level_index").val(level_index);
 		 }
function addnewmenu(){
 			 //初始化顶层菜单
 			$("#inintdata").html(defaultdata);
 		 }
function setVO(treeNode){
  			$("#men_sn").val(isNull(treeNode.men_sn));
 			$("#parent_sn").val(isNull(treeNode.parent_sn));
 			$("#level_index").val(isNull(treeNode.level_index));
 			$("#fomcat").val(isNull(treeNode.fomcat));
 			$("#men_name").val(isNull(treeNode.men_name));
 			$("#men_url").val(isNull(treeNode.men_url));
 			$("#level_seq").val(isNull(treeNode.level_seq));
 			$("#men_code").val(isNull(treeNode.men_code));
 			$("#old_men_code").val(isNull(treeNode.men_code));
 		 }
 		 //更具id查找节点
function searchNodeById(id){
 			var zTree = $.fn.zTree.getZTreeObj("tree1");
 			nodeList = zTree.getNodesByParam("id",id);
 			return nodeList[0];
 		 }
 		 //删除节点
function delNodeById(id){ 			 
 			$.fn.zTree.getZTreeObj("tree1").removeNode(searchNodeById(id));
 		 }
 		 //添加菜单
function addnode(newnode){
 			var parentnode=searchNodeById(newnode.parent_sn);
 			var zTree = $.fn.zTree.getZTreeObj("tree1");
 			zTree.addNodes(parentnode,newnode,false);
 		 }
 		 //更新节点
function updatenode(node){
	 		var node_new=searchNodeById(node.id);
	 		jQuery.extend(node_new,node);
 			$.fn.zTree.getZTreeObj("tree1").updateNode(node_new);
 		 }
 		
</SCRIPT>
</head>
  
  <body>
 
     <!-- 顶部 -->
	 <jsp:include page="/work/admin/comm/jsp/head.jsp"/>
    <!-- 顶部 end-->
    <div class="body clearfix">
	<!-- 菜单及返回顶部 -->
	<jsp:include page="/work/admin/comm/jsp/menu.jsp">
	     <jsp:param value="<%=AdminMenuConstant.ADMIN_SYSTEM %>" name="menu_parent_code"/>
	     <jsp:param value="<%=AdminMenuConstant.ADMIN_SYSTEM_MENU%>" name="menu_sub_code"/>
	</jsp:include>
	<!-- 菜单及返回顶部end -->	
	<!--导航-->
	<div style="margin-left:150px">
		<ul id="crumbs">
	<li><a href="<%=eduboat.dsch.comm.util.SchConstant.admin_defaul_url %>">首页</a></li>
	<li><a href="javascript:void(0)">系统管理</a></li>
	<li><a href="<%=path %>/work/admin/xtgl/menu/menu_index.jsp">后台菜单维护</a></li>
		<li>
    <!--帮助-->
        <div  class="report-help" title="点击查看帮助" onClick="slideToggle('ReportExam')"></div>
    <!--帮助 end-->
</li>
	</ul>
	</div>
			
	<!--导航 end-->
	
	<!--提示信息-->
	<div style="" id="ReportExam" class="report-tip">
				<div class="tip-arrow" style="left: 66px;"></div>
				<div class="report-tip-content">
					<table class="report-tip-table">
						<tr>
							<td width="95%" valign="top">
								<div class="left-content l">
								
								<p class="label">
								只有后台管理人员菜单才动态配置，前台菜单硬编码
								</p>
								</div>
							</td>
						</tr>
					</table>
				</div><!-- .report-tip-content -->
			</div><!-- #ReportExam, .report-tip -->
		<!--提示信息-->	
	<div class="main">
	  <div class="content clearfix">
	<!--菜单树-->
		<div class="bz_div" style="width:300px;height:450px; margin-top:0px;float:left;"> 
			<div class="bz_tit">
				<div style="margin-left:10px;" >后台菜单树</div>
   		 	</div>
		 	<div class="bz_cont">
			    <div style="width:100%;"> 
					<input type="button" class="inputOver" style="width:120px; margin-left:50px"  value="新增顶层菜单" onclick="addnewmenu()"/>
				</div>
		 	 	<div style="width:280px; height:390px; margin:0px; float:left; border:1px solid #ccc; overflow:auto;">
			     	<div id="tree1" class="ztree" style="display: none;text-align: center ;">
			     	 
			     	</div>
			     	<div id="tree1_load" class="ztree" style="text-align: center ;">
			     	  <img src="<%=path %>/comm/images/loading1.gif" alt="" />
			     	</div>
			    </div>
				
				
		 	</div><!--.bz_cont-->
	 </div><!--.bz_div-->
	  <!--菜单树 结束-->
	  
	   <!--菜单编辑页面-->
	   
	   <div class="bz_div" style="width:600px;height:450px; margin-top:0px; margin-left:20px;float:left;"> 
			<div class="bz_tit">
				<div style="margin-left:10px;" >菜单信息</div>
   		 	</div>
   		 	<form id="form1">
		 	<div class="bz_cont" id="inintdata">
				<table class="datadesr" style="width:98%;  margin-top:5px; margin-bottom:10px">
				
				<tr>
					<th style="width:80px; text-align:right" >菜单编码：<span class="red">*</span></th>
					<td >
					<input class="validate[required,ajax[checkXt_code]] inp" id="men_code" name="men_code">
					<input type="hidden" id="old_men_code" name="old_men_code"/>
					<span class="form_note">(唯一编码)</span>
					</td>
				</tr>
				<tr>
					<th style="width:80px; text-align:right" >菜单名：<span class="red">*</span></th>
					<td >
					<input class="validate[required] inp" id="men_name">
					</td>
				</tr>
				
				<tr>
					<th style="width:80px; text-align:right" >菜单连接</th>
					<td >
					<input class="inp" id="men_url"><span class="form_note">(一级菜单不需要连接)</span>
					</td>
				</tr>
				<tr>
					<th style="width:80px; text-align:right" >同层顺序：<span class="red">*</span></th>
					<td >
					<input class="validate[required,custom[integer]] inp" id="level_seq"><span class="form_note">(显示的先后顺序)</span>
					</td>
				</tr>
				<input id="men_sn" value="" style="display: none;"/>
				<input id="parent_sn" value="0" style="display: none;"/>
				<input id="level_index" value="1" style="display: none;"/>
				<input id="fomcat" value="" style="display: none;"/>
			  </table>
			  <div style="width:100%; text-align:center; margin-top:5px; margin-bottom:5px">
			   <input type="submit" value="保存" class="inputOver" style="width:60px">
			   <input id="btu_addsub" type="button" value="新增子菜单" class="inputOver" style="width:100px; margin-left:20px;display:none;" onclick="addsubmenu()" />
			   <input id="btu_del" type="button" value="删除" class="inputOver" style="width:80px; margin-left:20px;display: none;" onclick="del()"/>
			  </div>
		 	</div><!--.bz_cont-->
		 	</form>
	 </div><!--.bz_div-->
	  
	  
	  <!--菜单编辑页面 结束-->
	
	
 
  	 </div><!-- .content, clearfix -->
		<!-- 底部 -->
		<jsp:include page="/work/admin/comm/jsp/foot.jsp"/>
        <!-- 底部end -->
	</div><!-- .main -->
</div><!-- .body, .clearfix -->
  </body>
</html>
